#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>
#include<sys/wait.h>

int main()
{
  pid_t id=fork();
  if(id==0)
  {
    //子进程
    //ls -a -l
    printf("子进程开始运行，pid: %d\n",getpid());
    sleep(3);
    execl("/usr/bin/ls","ls","-a","-l",NULL);
    exit(1);
  }
  else 
  {
    //父进程
    printf("父进程开始运行，pid: %d\n",getpid());
    int status=0;
    pid_t res=waitpid(-1,&status,0);//阻塞等待
    if(res>0)
    {
      printf("wait success,exit code: %d\n",WEXITSTATUS(status));
    }
  }
  return 0;
}
